package JZOffer;

import java.util.Arrays;
import java.util.Comparator;

// https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
// 把数组排成最小的数
public class Day016_1 {
    public String minNumber(int[] nums) {
        String[] res = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(res, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1+o2).compareTo(o2+o1);
            }
        });

        StringBuilder stringBuilder = new StringBuilder();
        for (String s : res) {
            stringBuilder.append(s);
        }
        return stringBuilder.toString();
    }
}
